﻿
namespace Apache.Cassandra.Client {
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class ByteArrayComparer : IEqualityComparer<byte[]> {

        public static readonly ByteArrayComparer Default = new ByteArrayComparer();

        private ByteArrayComparer() {
        }

        public bool Equals(byte[] x, byte[] y) {
            if (x == null && y == null) {
                return true;
            }

            return x != null && x.SequenceEqual(y);
        }

        public int GetHashCode(byte[] obj) {
            if (obj == null) {
                throw new ArgumentNullException("obj");
            }

            return obj.Sum(x => x);
        }
    }
}
